package bTree.LeetCode;

import java.util.Arrays;

public class 最大交换 {
    public int maximumSwap(int num) {
        String string = Integer.toString(num);
        char[] charArray = string.toCharArray();
        Arrays.sort(charArray);
        int length = string.length();
        int j=length-1;
        for(int i=0;i<length;i++){
            if(string.charAt(i)!=charArray[j]){
                char[] charArray1 = string.toCharArray();
                int index=0;
                for(int i1=0;i<length;i1++){
                    if(charArray1[i1]==charArray[j]){
                        index=i1;
                    }
                }
                char c =charArray1[i];
                charArray1[i]=charArray1[index];
                charArray1[index]=charArray1[i];
                return Integer.parseInt(charArray1.toString());

            }
            j--;
        }
        return 1;
    }
}